package com.qingcheng.consumer;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.qingcheng.pojo.goods.Sku;
import com.qingcheng.service.goods.SkuService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

public class ElConsumer implements MessageListener {

    @Reference
    private SkuService skuService;
    @Override
    public void onMessage(Message message) {
        String jsonString = new String(message.getBody());
        System.out.println(jsonString);
        List<String> skuIds = JSON.parseArray(jsonString,String.class);
        List<Sku> skuList = new ArrayList<>();
        for (String skuId : skuIds) {
            Sku sku = skuService.findById(skuId);
            skuList.add(sku);
        }
        skuService.importToEs();
    }
}
